<?php
class ModeloformulariosController extends AppController {

	var $name = 'Modeloformularios';
    var $uses = array('Modeloformulario');

    function beforeFilter () {
        parent::beforeFilter();
    }
    
	function index() {
        $this->set('title_nav_bar','Modelos de Formularios');
		$this->set('modeloformularios', $this->paginate());
	}



    function edit($id=0) {

        if (isset($this->data['Modeloformulario']['save_apply'])) {
                if ($this->Modeloformulario->save($this->data['Modeloformulario'])) {
                    $this->Session->setFlash(__('Guardado correctamente', true));
                    $this -> redirect(array('action'=>'index'));
                    exit();                
                } else {
                    $this->Session->setFlash(__('No se pudo guardar el formulario.', true));
                }  
        } else {
            
            if ($id == 0) {
                $this->set('title_nav_bar','Crear un Modelo de Formulario');
                // Nuevo Formulario
                // obtain default values for new form
                $T = $this->Modeloformulario->_schema;
                foreach($T as $clave => $valor) { $this->data['Modeloformulario'][$clave] = $valor['default']; }
                $this->data['Modeloformulario']['id'] = 0;    
            } else {
                $this->set('title_nav_bar','Editar Modelo de Formulario (id:'.$id.')');
                $this->data= $this->Modeloformulario->read(null, $id);
            }
            
        }
        
    }


	function delete() {

		if (empty($this->data['Delete'])) {
			$this->Session->setFlash(__('Debe seleccionar un Modelo de Formulario', true));
			$this->redirect(array('action'=>'index'));
		} else {
 
            foreach($this->data['Delete'] as $key=>$value) {
                if ($value==1) { 
                    $this->Modeloformulario->delete($key,true); 
                }
            }
            $this->Session->setFlash(__('Modelo de Formulario eliminado', true));
    		$this->redirect(array('action'=>'index'));

		} 
	}

}
